<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace AlibabaCloud\Client\Request;

class RpcRequest extends Request
{
    private $dateTimeFormat = "Y-m-d\\TH:i:s\\Z";
    public function resolveParameter()
    {
        $this->resolveBoolInParameters();
        $this->resolveCommonParameters();
        $this->repositionParameters();
    }
    private function resolveBoolInParameters()
    {
        if(isset($this->options["query"])) {
            $this->options["query"] = array_map(function ($value) {
                return self::boolToString($value);
            }, $this->options["query"]);
        }
    }
    public static function boolToString($value)
    {
        if(is_bool($value)) {
            return $value ? "true" : "false";
        }
        return $value;
    }
    private function resolveCommonParameters()
    {
        $signature = $this->httpClient()->getSignature();
        $this->options["query"]["RegionId"] = $this->realRegionId();
        $this->options["query"]["Format"] = $this->format;
        $this->options["query"]["SignatureMethod"] = $signature->getMethod();
        $this->options["query"]["SignatureVersion"] = $signature->getVersion();
        $this->options["query"]["SignatureNonce"] = \AlibabaCloud\Client\Support\Sign::uuid($this->product . $this->realRegionId());
        $this->options["query"]["Timestamp"] = gmdate($this->dateTimeFormat);
        $this->options["query"]["Action"] = $this->action;
        if($this->credential()->getAccessKeyId()) {
            $this->options["query"]["AccessKeyId"] = $this->credential()->getAccessKeyId();
        }
        if($signature->getType()) {
            $this->options["query"]["SignatureType"] = $signature->getType();
        }
        if(!isset($this->options["query"]["Version"])) {
            $this->options["query"]["Version"] = $this->version;
        }
        $this->resolveSecurityToken();
        $this->resolveBearerToken();
        $this->options["query"]["Signature"] = $this->signature();
    }
    private function resolveSecurityToken()
    {
        if(!$this->credential() instanceof \AlibabaCloud\Client\Credentials\StsCredential) {
            return NULL;
        }
        if(!$this->credential()->getSecurityToken()) {
            return NULL;
        }
        $this->options["query"]["SecurityToken"] = $this->credential()->getSecurityToken();
    }
    private function resolveBearerToken()
    {
        if($this->credential() instanceof \AlibabaCloud\Client\Credentials\BearerTokenCredential) {
            $this->options["query"]["BearerToken"] = $this->credential()->getBearerToken();
        }
    }
    private function signature()
    {
        return $this->httpClient()->getSignature()->sign($this->stringToSign(), $this->credential()->getAccessKeySecret() . "&");
    }
    public function stringToSign()
    {
        $query = isset($this->options["query"]) ? $this->options["query"] : [];
        $form_params = isset($this->options["form_params"]) ? $this->options["form_params"] : [];
        $parameters = \AlibabaCloud\Client\Support\Arrays::merge([$query, $form_params]);
        return \AlibabaCloud\Client\Support\Sign::rpcString($this->method, $parameters);
    }
    private function repositionParameters()
    {
        if($this->method === "POST" || $this->method === "PUT") {
            foreach ($this->options["query"] as $api_key => $api_value) {
                $this->options["form_params"][$api_key] = $api_value;
            }
            unset($this->options["query"]);
        }
    }
    public function __call($name, $arguments)
    {
        if(strncmp($name, "get", 3) === 0) {
            $parameter_name = mb_strcut($name, 3);
            return $this->__get($parameter_name);
        }
        if(strncmp($name, "with", 4) === 0) {
            $parameter_name = mb_strcut($name, 4);
            $this->__set($parameter_name, $arguments[0]);
            $this->options["query"][$parameter_name] = $arguments[0];
            return $this;
        }
        if(strncmp($name, "set", 3) === 0) {
            $parameter_name = mb_strcut($name, 3);
            $with_method = "with" . $parameter_name;
            throw new \RuntimeException("Please use " . $with_method . " instead of " . $name);
        }
        throw new \RuntimeException("Call to undefined method AlibabaCloud\\Client\\Request\\RpcRequest::" . $name . "()");
    }
}

?>